<!DOCTYPE html>
<html lang='zh-CN'>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>驿站收货表</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">

</head>
<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">
                    <h4>订单收货</h4>
                    <div id="toolbar" class="toolbar-btn-action">
                        <form class="form-inline" method="post" id="searchForm">
                            <div class="form-group">
                                <label>支付时间:</label>
                                <input type="text" class="form-control js-datepicker" data-date-format="yyyy-mm-dd" name="startTime" placeholder="开始时间" style="width:120px;"> -
                                <input type="text" class="form-control js-datepicker" data-date-format="yyyy-mm-dd" name="endTime" placeholder="结束时间" style="width:120px;">
                            </div>
                            <div class="form-group">
                                <label>订单号:</label>
                                <input type="text" class="form-control" name="outTradeNo">
                            </div>
<!--                            <div class="form-group">-->
<!--                                <label>驿站账号:</label>-->
<!--                                <input type="text" class="form-control" name="stationId">-->
<!--                            </div>-->
                            <div class="form-group">
                                <label>订单状态:</label>
                                <select name="orderState" class="form-control">
                                    <option value="">全部</option>
                                    <option value="3">已完成订单</option>
                                    <option value="4">未完成订单</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-info btn_query btn-round"  type="button" id="searchFormBtn">查询</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-purple btn_query btn-round" type="button" id="watchBtn">商品详情</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-success btn_query btn-round" type="button" id="confirmReceipt">确认收货</button>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="card-body">
                    <table id="list_data"></table>
                </div>
            </div>
        </div>
    </div>

    <!--  驿站详细模态框 -->
    <div class="modal fade" id="ProductDetailsModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabels">
        <div class="modal-dialog" role="document" style="width: 60%;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="ProductInformation">商品内容</h4>
                </div>
                <div class="modal-body" id="commodityMessage"></div>
            </div>
        </div>
    </div>



    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
    <script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
    <!-- bootstrap表单验证插件 -->
    <script type="text/javascript" src="js/bootstrap-validator-master/dist/validator.js"></script>
    <!-- jquery-form表单提交插件 -->
    <script type="text/javascript" src="js/jquery-form/jquery.form.js"></script>
    <!-- bootstrap弹出框插件 -->
    <script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
    <!-- 表单填充插件 -->
    <script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>
    <!--日期选择插件-->
    <script src="js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
    <script src="js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
    <script type="text/javascript" src="js/main.min.js"></script>

    <script type="text/javascript">



        //设置表头
        var columns = [
            {checkbox: true},
            {field: 'outTradeNo',title: '订单号'},
            {field: 'stationId',title: '驿站账号',visible: false},
            {field: 'stationName',title: '驿站名称'},
            {field: 'orderAmount',title: '订单总金额'},
            {field: 'goodItems',title: '----------------------------------商品------------------------------------',formatter: function (value, row, index) {
                    var jsonObj =  JSON.parse(value);
                    var content='';
                    for (let i = 0; i <jsonObj.length ; i++) {
                        content+=
                            '<label style="font-size: small">商品（'+(i+1)+'）标题：</label><label style="font-size: small">'+jsonObj[i].productName+'</label>'
                            +'<label style="font-size: small">,购买数：</label><label style="font-size: small">'+jsonObj[i].count+'</label>'
                            +'<label style="font-size: small">,价格：</label><label style="font-size: small">'+jsonObj[i].fnPrice+'</label>'
                            +'<label style="font-size: small">,规格：</label><label style="font-size: small">'+jsonObj[i].skuAttr+'</label>'
                            +'<br>'
                    }
                    return content;
                }},
            {field: 'createTime',title: '订单创建时间',formatter: function (value) {
                    return zero2one.dateFormat(value, 'Y-m-d H:i:s')
                }},
            {field: 'orderState',title: '订单状态',formatter: function (value, row, index) {
                    if (value=='0') {
                        return  "<button class=\"btn btn-warning btn-sm\">待付款</button>";
                    }else if(value=='1'){
                        return  "<button class=\"btn btn-warning btn-sm\">待收货</button>";
                    }else if(value=='2'){
                        return  "<button class=\"btn btn-warning btn-sm\">待取货</button>";
                    }else if(value=='3'){
                        return  "<button class=\"btn btn-success btn-sm\">已完成</button>";
                    }else if(value=='4'){
                        return  "<button class=\"btn btn-danger btn-sm\">已关闭</button>";
                    }else if(value=='5'){
                        return  "<button class=\"btn btn-primary btn-sm\">取消订单</button>";
                    }else if(value=='6'){
                        return  "<button class=\"btn btn-warning btn-sm\">审核中</button>";
                    }else if(value=='7'){
                        return  "<button class=\"btn btn-success btn-sm\">审核成功</button>";
                    }else if(value=='8'){
                        return  "<button class=\"btn btn-danger btn-sm\">审核失败</button>";
                    }else if(value=='9'){
                        return  "<button class=\"btn btn-success btn-sm\">付款成功</button>";
                    }else if(value=='10'){
                        return  "<button class=\"btn btn-danger btn-sm\">业务处理失败</button>";
                    }else if(value=='11'){
                        return  "<button class=\"btn btn-primary btn-sm\">撤销退款申请</button>";
                    }
                }},
            {field: 'memberPhone',title: '手机号码', formatter: function (value) {
                    if (value==null || value==''){
                        return  "无";
                    }else {
                        return value;
                    }
                }},
            {field: 'address',title: '收货地址',formatter: function (value, row, index) {
                    var bToObj=JSON.parse(value);//json数据组解析   换行：' \n '
                    for (let i = 0; i <value.length ; i++) {
                        if (bToObj==null || bToObj=='') {
                            return  "无";
                        }else{
                            return "姓名："+bToObj.receiverName+' \n '+"电话："+bToObj.receivePhone+' \n '+"地址："+bToObj.provinceName+bToObj.cityName+bToObj.regionName +bToObj.streetAddr;
                        }
                    }
                }},
            {field: 'payTime',title: '支付时间',formatter: function (value) {
                    if (value==null){
                        return  "无";
                    }
                    return zero2one.dateFormat(value, 'Y-m-d H:i:s')
                }},
            {field: 'deliveryTime',title: '发货时间',formatter: function (value) {
                    if (value==null){
                        return  "无";
                    }
                    return zero2one.dateFormat(value, 'Y-m-d H:i:s')
                }},
            {field: 'confirmTime',title: '收货时间',formatter: function (value) {
                    if (value==null){
                        return  "无";
                    }
                    return zero2one.dateFormat(value, 'Y-m-d H:i:s')
                }},
            {field: 'payType',title: '支付渠道',formatter: function (value, row, index) {
                    if (value=='pearl') {
                        return  "珍珠";
                    }else if(value=='alipay'){
                        return  "支付宝";
                    }else if(value=='wxpay'){
                        return  "微信";
                    }
                }},
            {field: 'receiveType',title: '取货方式',formatter: function (value, row, index) {
                    if (value=='0') {
                        return  "<button class=\"btn btn-success btn-sm\">到店取货</button>";
                    }else if(value=='1'){
                        return  "<button class=\"btn btn-primary btn-sm\">邮寄</button>";
                    }
                }},
            {field: 'receiveCode',title: '取货码'},
            {field: 'presentExp',title: '赠送积分'},
            {field: 'presentVoucher',title: '赠送金卷'},
            {field: 'goodNumber',title: '商品数量'},
            {field: 'id',title: '订单编号'},
            {field: 'memberId',title: '会员账号'},
            {field: 'commission',title: '佣金'},
            {field: 'note',title: '订单备注'}
        ];


        //进入主界面加载数据
        zero2one.datagrid("list_data", "/remote/StationOrder/list",function (params) {
            return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchForm"));
        }, columns);

        //点击查询按钮重新加载页面数据
        $("#searchFormBtn").click(function () {
            $('#list_data').bootstrapTable('refresh');
        });


        //点击商品详情
        $("#watchBtn").click(function () {
            //获取选中行的数据
            var datas = $('#list_data').bootstrapTable('getSelections');
            //判断是否选中行数据，如果没有则提示
            if(datas.length == 1&&datas[0].goodItems!=''){

                var jsonObj =  JSON.parse(datas[0].goodItems);//json字符串转化成json对象（原生方法）

                var content='';
                for (let i = 0; i <jsonObj.length ; i++) {
                    content+=
                        '<label style="font-size: x-large">标题：</label><label style="font-size: large">'+jsonObj[i].productName+'</label></br>'
                        +'<label style="font-size: x-large">计数：</label><label style="font-size: large">'+jsonObj[i].count+'</label></br>'
                        +'<label style="font-size: x-large">skuId：</label><label style="font-size: large">'+jsonObj[i].skuId+'</label></br>'
                        +'<label style="font-size: x-large">积分：</label><label style="font-size: large">'+jsonObj[i].giveJf+'</label></br>'
                        +'<label style="font-size: x-large">金券：</label><label style="font-size: large">'+jsonObj[i].needJq+'</label></br>'
                        +'<label style="font-size: x-large">价格：</label><label style="font-size: large">'+jsonObj[i].fnPrice+'</label></br>'
                        +'<label style="font-size: x-large">规格：</label><label style="font-size: large">'+jsonObj[i].skuAttr+'</label></br>'
                        +'<label style="font-size: x-large">产品编号：</label><label style="font-size: large">'+jsonObj[i].productId+'</label></br>'
                        +'<label style="font-size: x-large">优惠券：</label><label style="font-size: large">'+jsonObj[i].giveVoucher+'</label></br>'
                        +'<label style="font-size: x-large">商品总价格：</label><label style="font-size: large">'+jsonObj[i].marketPrice+'</label></br>'
                        +'<label style="font-size: x-large">产品库存：</label><label style="font-size: large">'+jsonObj[i].productStock+'</label></br>'
                        +'<label style="font-size: larger">图片:</label></br>'+"<img style='width: auto;height: auto;border-radius: 10%'  src='"+jsonObj[i].picture+"'/>"+'</br>'
                        +'<hr>'
                }
                $("#commodityMessage").html(content);
                //打开模态框
                $("#ProductDetailsModal").modal("show");

            }else{
                $.messager.alert("温馨提示", "请选择一条数据操作");
            }
        });


        //点击确认收货按钮
        $("#confirmReceipt").click(function () {
            //获取选中行的数据
            var datas = $('#list_data').bootstrapTable('getSelections');
            //判断是否选中行数据，如果没有则提示
            if(datas.length == 1){
                 if (datas[0].orderState == 1 || datas[0].orderState == 2){
                    $.messager.confirm("温馨提示", "您是否确定要更改订单状态为：“已完成”?", function () {
                        //发送请求,执行批量删除
                        zero2one.request("/remote/yzConfirmReceive",{"orderId": zero2one.array2str(datas)},function (data) {
                            window.setTimeout("window.location.reload()",1000);//延迟1秒刷新
                        });
                    })
                }else{
                    $.messager.alert("温馨提示", "您的订单状态已满足条件，无需要更改");

                }
            }else{
                $.messager.alert("温馨提示", "请选择一条数据操作");

            }
        });

    </script>
</div>
</body>
</html>

